package im.starchat.chat.utils;

import im.starchat.chat.XLApplication;
import im.starchat.chat.rest.model.UserBean;
import im.starchat.chat.rest.model.api.LoginResponse;

/**
 * Created by liuchao on 3/10/16.
 */
public class UserUtils {

    private static UserBean sUserInstance;

    public static UserBean getUserInstance(){
        if(sUserInstance == null){
            sUserInstance = PreferencesStorageUtil.getUserBean(XLApplication.getInstance());
            if(sUserInstance == null){
                sUserInstance = new UserBean();
            }
        }
        return sUserInstance;
    }

    public static void setUserInstance(UserBean userBean){
        sUserInstance = userBean;
    }

    public static UserBean transLoginRes2User(LoginResponse response){
        UserBean userBean = new UserBean();
        userBean.setAddress(response.getAddress());
        userBean.setAuthentication_token(response.getAuthentication_token());
        userBean.setAvatar(response.getAvatar());
        userBean.setDescription(response.getDescription());
        userBean.setGender(response.getGender());
        userBean.setId(response.getId());
        userBean.setNew_user(response.isNew_user());
        userBean.setNickname(response.getNickname());
        userBean.setTsig(response.getTsig());
        userBean.setUser_type(response.getUser_type());
        return userBean;
    }

}
